/**
 @desc 无限加载插件
*/
(function($){
	$.fn.loding = function(option){
		var option = $.extend({},$.fn.loding.defaults,option);
		$(window).scroll(function(){
			var divHeight = $(option.loading_id).height();
			var broHeight = $(window).outerHeight();
			var scrolltop = $(window).scrollTop();
			var scrBottom = (divHeight-broHeight)-105;
			var inner = $(option.ajax_loading).attr('class','dl-loding');
			var page_num = Number($(option.page_num).text());
			if(page_num > 0){//判断page_num 是否小于0 大于0标识数据还有没加载出来的 小于0表示数据已经加载完了
				if(scrolltop >scrBottom ){//判断滚动条的距离底部的距离
					if($('.dl-loding').length == 0){//排除一次请求多次数据
						$(option.loading_id).append($(inner));
						$.ajax({
							'url' : option.ajax_url,
							'type' : "POST",
							'cache': false,
							'data':{"page_num":page_num,"show_num":option.show_num},
							'success' : function(data, textStatus){
									$(option.page_num).remove();
									$(inner).remove();
									$('.dl-content').append($(data));
								}
						});
					};
				};
			};
		});
	};
	//返回顶部创建
	$.fn.loding.returntop = function(){
		var top = $.fn.loding.defaults.return_top;
		$(top).appendTo($('body'));
		var bt = $('#toolBackTop');
        var sw = $(document.body)[0].clientWidth;
        var limitsw = (sw - 840) / 2 - 80;
        if (limitsw > 0){
                limitsw = parseInt(limitsw);
                bt.css("right",limitsw);
        }

        $(window).scroll(function() {
                var st = $(window).scrollTop();
                if(st > 30){
                        bt.show();
                }else{
                        bt.hide();
                }
        });
	}
	$.fn.loding.defaults = {
		'loading_id': '.dl-content',//无限加载的内容标识
		'ajax_url': '/wuxian/getAjaxData',//ajax请求的url
		'page_num' : '#page_num',//标识从数组开始的数的div ID
		'show_num' : 5,//每次ajax请求的返回的数量
		'ajax_loading': '<div style="padding:20px 0 20px; text-align:center; line-height:16px;"><img class="vm" src="img/loading.gif" border=0 />正在加载，请稍侯...</div>'	,
		'return_top': '<div style="display:none;" class="back-to" id="toolBackTop"><a title="返回顶部" onclick="window.scrollTo(0,0);return false;" href="#top" class="back-top">返回顶部</a></div>'
	}
})(jQuery)